const Koa = require('koa');
//Application
const app = new  Koa();
//路由
const router = require('koa-router')();
const responseFormatter = require('./middlewares/responseFormater');

//只过滤test路径下的接口
app.use(responseFormatter('^/test'));

router.get('/test/getApi',async (context,next) => {
  context.response.type = 'text/html';
  context.response.body = 'Hello, Get Request!';
});

router.post('/test/postApi',async (context,next) => {
  context.response.type = 'text/html';
  context.response.body = 'Hello, Post Request!';
});

router.get('/users/getUser',async (context,next) => {
  context.response.body = {
    name:'zhangsan',
    sex:1,
    age:21
  };
});

//使用路由
app.use(router.routes());

//开启服务,监听3001端口
app.listen(3001);

console.log(`process.env.NODE_ENV: ${process.env.NODE_ENV}`);
